package com.jl15988.chainlog.config;

import com.jl15988.chainlog.aspect.ChainApiAspect;
import com.jl15988.chainlog.aspect.ChainMethodAspect;
import com.jl15988.chainlog.callback.TraceCollectorCallback;
import com.jl15988.chainlog.manual.ChainLogHelper;
import com.jl15988.chainlog.manual.ChainLogManual;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * 链式日志自动配置类
 */
@Configuration
@EnableAspectJAutoProxy
@EnableConfigurationProperties(ChainLogProperties.class)
@ConditionalOnProperty(prefix = "chain-log.monitor", name = "enabled", havingValue = "true", matchIfMissing = true)
public class ChainLogAutoConfiguration {

    /**
     * 接口监控切面
     */
    @Bean
    public ChainApiAspect chainApiAspect() {
        return new ChainApiAspect();
    }

    /**
     * 链式监控切面
     */
    @Bean
    public ChainMethodAspect chainMethodAspect() {
        return new ChainMethodAspect();
    }

    /**
     * 手动监控工具
     */
    @Bean
    public ChainLogManual manualMonitor() {
        return new ChainLogManual();
    }

    /**
     * 监控助手
     */
    @Bean
    public ChainLogHelper monitorHelper() {
        return new ChainLogHelper();
    }

//    /**
//     * 链式跟踪服务
//     */
//    @Bean
//    @ConditionalOnMissingBean(ChainTraceService.class)
//    public ChainTraceService chainTraceService() {
//        return new MemoryChainTraceService();
//    }

    /**
     * 跟踪数据收集回调
     */
    @Bean
    public TraceCollectorCallback traceCollectorCallback() {
        return new TraceCollectorCallback();
    }

    /**
     * 可视化控制器
     */
//    @Bean
//    @ConditionalOnProperty(prefix = "chain-log.visualization", name = "enabled", havingValue = "true", matchIfMissing = true)
//    public ChainTraceController chainTraceController() {
//        return new ChainTraceController();
//    }
}